package com.starchen.optimalselection.web.controller;

import com.starchen.optimalselection.common.utils.Result;
import com.starchen.optimalselection.web.model.Member;
import com.starchen.optimalselection.web.model.vo.MemberVo;
import com.starchen.optimalselection.web.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author daxilong
 * @date 2024/11/6 11:13
 */

@RestController
@Api(tags = "微信登录")
@RequestMapping("/api/wx")
public class WxLoginController {

    @Autowired
    private MemberService memberService;

    @ApiOperation(value = "小程序授权登录")
    @GetMapping("/login/{code}")
    public Result login(@PathVariable String code) {
        String token = memberService.login(code);

        Map<String,Object> map = new HashMap<>();
        map.put("token",token);
        return Result.success(map);
    }

    @ApiOperation(value = "获取客户登录信息")
    @GetMapping("/userinfo")
    public Result<MemberVo> getCustomerLoginInfo(@RequestHeader(value = "token") String token) {

        MemberVo customerLoginVo = memberService.getUserInfo(token);
        return Result.success(customerLoginVo);
    }

    @ApiOperation(value = "更新用户名")
    @PostMapping("/update")
    public Result updateInfo(@RequestBody Member member) {
        memberService.updateById(member);
        return Result.success();
    }

}
